#include<stdio.h>
#include"mythread.h"
#include<stdlib.h>
#include<unistd.h>


extern PtrTCB Mcurrent;

void func2();

void func1()
{
    int times = 1;
    int i;
    for (i = 0;i < 7;i++)
    {
        printf("hello world 1:%d\n", times);
        times++;
    }
}



void func2()
{
    int times = 1;
    int i;
    for (i = 0;i < 1;i++)
    {
        printf("hello world 2:%d\n", times);
        times++;

    }
      MyYield();
}

void func3()
{
    int times = 1;
    int i;
    for (i = 0;i < 6;i++)
    {
        printf("hello world 3:%d\n", times);
        times++;
        MyYield();
    }

}

void func4()
{
    int times = 1;
    int i;
    for (i = 0;i < 3;i++)
    {
        printf("hello world 4:%d\n", times);
        times++;
    }
 MyYield();
}


int main()
{
    printf("main runing!\n");
    int id1, id2, id3, id4;
    thread_create(&id1, func1);
    thread_create(&id2, func2);
    thread_create(&id3, func3);
    thread_create(&id4, func4);

    while (1)
    {
        /* code */
        printf("main runing!\n");
        MyYield();
        if(Mcurrent->id==0)break;
    }
    Mythreadfree(id1);
    Mythreadfree(id2);
    Mythreadfree(id3);
    Mythreadfree(id4);
    return 0;
}
